//
//  BaseTableViewContreoller.swift
//  SinaWeibo
//
//  Created by 周小伟 on 16/8/22.
//  Copyright © 2016年 周小伟. All rights reserved.
//

import UIKit

class BaseTableViewContreoller: UITableViewController,VisitorLoginViewDelegate {
    
    //Add a flag for record if user have log in the application
    var userLogin = UserAccountViewModel().userLogin
    var visitorLoginView:VisitorLoginView?
    
    //if you have realized this function, the xib or storyboard will lost their function!
    //this funtion is Apple prepare for coding by yourself!
    override func loadView() {
        //if the view is nil,the controller will circular to find the view!
//        print(self.view)
        userLogin ? super.loadView() : loadVisitorView()
    }
    
    private func loadVisitorView(){
        visitorLoginView = VisitorLoginView()
        
        visitorLoginView?.visitorDelegate = self
        
        self.view = visitorLoginView
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseTableViewContreoller.visitorWillRegister))
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseTableViewContreoller.visitorWillLogin))
        
    }
    
    func visitorWillLogin() {
        print("come in")
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        self.presentViewController(nav, animated: true, completion: nil)
    }
    
    func visitorWillRegister() {
        print("come on")
    }
    
    
    
    
    
    
    //viewDidLoad
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

}
